<?php
namespace BackHome\Controller;
use Think\Controller;
class ArticleController extends CommonController {
    public function index(){
        $this->show('该页面留作统计用','utf-8');
    }//end fun
	/*******************************************************************************/
	//地方贤达
    public function celebrity(){
        $arc_celebrity = M('arc_celebrity'); // 实例化对象
		$count      = $arc_celebrity->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,20);// 实例化分页类 传入总记录数和每页显示的记录数(25)
		$show       = $Page->show();// 分页显示输出
		// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
		$list = $arc_celebrity->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
		$newlist=array();
		foreach($list as $one){
			//后面id.title被覆盖，所以重新保存
			$one['arc_celebrity_id']=$one['id'];
			$one['arc_celebrity_title']=$one['title'];
			//原生态写法-查乡村信息
			$Model = M();
			$sql="SELECT (select name from `tv_area` where id=v.area_lev_1)as a1,(select name from `tv_area` where id=v.area_lev_2)as a2,(select name from `tv_area` where id=v.area_lev_3)as a3,(select name from `tv_area` where id=v.area_lev_4)as a4,(select name from `tv_area` where id=v.area_lev_5)as a5,v.* FROM `tv_village` v WHERE id=".$one['v_id']." order by id desc";
			$getall=$Model->query($sql);
			
			//查用户微信信息
			$user=D('user');
			$getwx=$user->where("id=".$one['u_id'])->find();
			//查用户姓名
			$user_info=D('user_info');
			$getinfo=$user_info->where("u_id=".$one['u_id'])->find();
			
			$newlist[]=array_merge($one,$getall[0],$getwx,(array)$getinfo);//合并数组其中一个为null，结果为null，需要强制类型转换(array)
		}//end for
		//dump($newlist);
		$this->assign('list',$newlist);// 赋值数据集
		$this->assign('page',$show);// 赋值分页输出
		//dump($show);
		$this->display(); // 输出模板
    }//end fun
	//添加
	public function celebrity_add(){
		$this->display(); // 输出模板
	}//end fun
	public function celebrity_ins(){
		$arc_celebrity=D('arc_celebrity');
		$data=array();
		//单文件上传
		if($_FILES['img']["name"]!=''){
			$upload = new \Think\Upload();// 实例化上传类
			$upload->maxSize   =     3145728 ;// 设置附件上传大小
			$upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
			$upload->rootPath  =      './Public/Uploads/'; // 设置附件上传根目录
			$upload->autoSub = false;	//关闭日期类型子目录自动生成
			$upload->savePath  =      'celebrity/'; // 设置附件上传（子）目录
			// 上传单个文件 
			$info   =   $upload->uploadOne($_FILES['img']);
			if(!$info) {// 上传错误提示错误信息
				$this->error($upload->getError());
			}else{// 上传成功 获取上传文件信息
				 $data['img']=$info['savepath'].$info['savename'];
			}
		}
		if($_POST['u_id']==0 || $_POST['v_id']==0)$this->error("添加失败，村庄和书记为必填项！");
		$data['u_id']=$_POST['u_id'];
		$data['v_id']=$_POST['v_id'];
		$data['title']=$_POST['title'];
		$data['content']=$_POST['content'];
		$data['addtime']=time();
		$data['uptime']=time();
		$alt=$arc_celebrity->add($data);
		if($alt>0){
			$this->success('添加成功', '/BackHome/Article/celebrity/');
			}else{
				    //错误页面的默认跳转页面是返回前一页，通常不需要设置
    				$this->error('新增失败');
			}
	}//end fun
	
	//编辑
	public function celebrity_edit(){
		$arc_celebrity=D('arc_celebrity');
		if(is_numeric($_GET['id'])){
			$data=array();
			$data=$arc_celebrity->where("id=".$_GET['id'])->find();
			$this->assign('info',$data);
			//村庄
			$village=D('village');
			$getv=$village->where('id='.$data['v_id'])->find();
			$area=D('area');
			$getarea=$area->where("id=".$getv['area_lev_1'])->find();
			$getv['a1']=$getarea['name'];
			$getarea=$area->where("id=".$getv['area_lev_2'])->find();
			$getv['a2']=$getarea['name'];
			$getarea=$area->where("id=".$getv['area_lev_3'])->find();
			$getv['a3']=$getarea['name'];
			$getarea=$area->where("id=".$getv['area_lev_4'])->find();
			$getv['a4']=$getarea['name'];
			$getarea=$area->where("id=".$getv['area_lev_5'])->find();
			$getv['a5']=$getarea['name'];
			$this->assign('vinfo',$getv);
			//书记
			$user=D('user');
			$getva=$user->where("id=".$data['u_id'])->find();
			$this->assign('vainfo',$getva);
			
		}//end if
		$this->display(); // 输出模板
	}//end fun
	
	//文章更新
	public function celebrity_upd(){
		$arc_celebrity=D('arc_celebrity');
		if(is_numeric($_POST['id'])){
			$data=array();
			//单文件上传
			if($_FILES['img']["name"]!=''){
				$upload = new \Think\Upload();// 实例化上传类
				$upload->maxSize   =     3145728 ;// 设置附件上传大小
				$upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
				$upload->rootPath  =      './Public/Uploads/'; // 设置附件上传根目录
				$upload->autoSub = false;	//关闭日期类型子目录自动生成
				$upload->savePath  =      'celebrity/'; // 设置附件上传（子）目录
				// 上传单个文件 
				$info   =   $upload->uploadOne($_FILES['img']);
				if(!$info) {// 上传错误提示错误信息
					$this->error($upload->getError());
				}else{// 上传成功 获取上传文件信息
					 $data['img']=$info['savepath'].$info['savename'];
				}
			}
			$data['u_id']=$_POST['u_id'];
			$data['v_id']=$_POST['v_id'];
			$data['title']=$_POST['title'];
			$data['content']=$_POST['content'];
			$data['uptime']=time();
			$alt=$arc_celebrity->where("id=".$_POST['id'])->save($data);
			if($alt>0){
				$this->success('更新成功', '/BackHome/Article/celebrity/');
				}else{
						//错误页面的默认跳转页面是返回前一页，通常不需要设置
						$this->error('更新失败');
				}
		}//end if
	}//end fun
	//删除
	public function celebrity_del(){
		$arc_celebrity=D('arc_celebrity');
		$getone=$arc_celebrity->where("id=".$_GET['id'])->find();//dump($getone);
		//先删除图片
		if($getone['img']!=''){
			$file = './Public/Uploads/'.$getone['img'];
			if (!unlink($file))
			  {
			  echo ("删除文件失败 $file");
			  }
			else
			  {
			  echo ("成功删除 $file");
			  }
		}
		$alt=$arc_celebrity->where("id=".$_GET['id'])->delete();
		if($alt>0){
			$this->success('删除成功', '/BackHome/Article/celebrity/');
			}else{
				$this->error('删除失败');
			}
	}//end fun
	/*******************************************************************************/
	//第一书记日志
    public function diary(){
        $arc_diary = M('arc_diary'); // 实例化对象
		$count      = $arc_diary->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,100);// 实例化分页类 传入总记录数和每页显示的记录数(25)
		$show       = $Page->show();// 分页显示输出
		// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
		$list = $arc_diary->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
		$newlist=array();
		foreach($list as $one){
			//后面id.title被覆盖，所以重新保存
			$one['arc_diary_id']=$one['id'];
			$one['arc_diary_title']=$one['title'];
			//原生态写法-查乡村信息
			$Model = M();
			$sql="SELECT (select name from `tv_area` where id=v.area_lev_1)as a1,(select name from `tv_area` where id=v.area_lev_2)as a2,(select name from `tv_area` where id=v.area_lev_3)as a3,(select name from `tv_area` where id=v.area_lev_4)as a4,(select name from `tv_area` where id=v.area_lev_5)as a5,v.* FROM `tv_village` v WHERE id=".$one['v_id']." order by id desc";
			$getall=$Model->query($sql);
			
			//查用户微信信息
			$user=D('user');
			$getwx=$user->where("id=".$one['u_id'])->find();
			//查用户姓名
			$user_info=D('user_info');
			$getinfo=$user_info->where("u_id=".$one['u_id'])->find();
			
			$newlist[]=array_merge($one,$getall[0],$getwx,(array)$getinfo);//合并数组其中一个为null，结果为null，需要强制类型转换(array)
		}//end for
		//dump($newlist);
		$this->assign('list',$newlist);// 赋值数据集
		$this->assign('page',$show);// 赋值分页输出
		//dump($show);
		$this->display(); // 输出模板
    }//end fun
	//添加
	public function diary_add(){
		
		$this->display(); // 输出模板
	}//end fun
	public function diary_ins(){
		$arc_diary=D('arc_diary');
		$data=array();
		//单文件上传
		//dump($_FILES['img']);return;
		if($_FILES['img']["name"]!=''){
			$upload = new \Think\Upload();// 实例化上传类
			$upload->maxSize   =     3145728 ;// 设置附件上传大小
			$upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
			$upload->rootPath  =      './Public/Uploads/'; // 设置附件上传根目录
			$upload->autoSub = false;	//关闭日期类型子目录自动生成
			$upload->savePath  =      'diary/'; // 设置附件上传（子）目录
			// 上传单个文件 
			$info   =   $upload->uploadOne($_FILES['img']);
			if(!$info) {// 上传错误提示错误信息
				$this->error($upload->getError());
			}else{// 上传成功 获取上传文件信息
				 $data['img']=$info['savepath'].$info['savename'];
			}
		}
		if($_POST['u_id']==0 || $_POST['v_id']==0)$this->error("添加失败，村庄和书记为必填项！");
		$data['u_id']=$_POST['u_id'];
		$data['v_id']=$_POST['v_id'];
		$data['title']=$_POST['title'];
		$data['content']=$_POST['content'];
		$data['addtime']=time();
		$data['uptime']=time();
		$alt=$arc_diary->add($data);
		if($alt>0){
			$this->success('添加成功', '/BackHome/Article/diary/');
			}else{
				    //错误页面的默认跳转页面是返回前一页，通常不需要设置
    				$this->error('新增失败');
			}
	}//end fun
	//编辑
	public function diary_edit(){
		$arc_diary=D('arc_diary');
		if(is_numeric($_GET['id'])){
			$data=array();
			$data=$arc_diary->where("id=".$_GET['id'])->find();
			$this->assign('info',$data);
			//村庄
			$village=D('village');
			$getv=$village->where('id='.$data['v_id'])->find();
			$area=D('area');
			$getarea=$area->where("id=".$getv['area_lev_1'])->find();
			$getv['a1']=$getarea['name'];
			$getarea=$area->where("id=".$getv['area_lev_2'])->find();
			$getv['a2']=$getarea['name'];
			$getarea=$area->where("id=".$getv['area_lev_3'])->find();
			$getv['a3']=$getarea['name'];
			$getarea=$area->where("id=".$getv['area_lev_4'])->find();
			$getv['a4']=$getarea['name'];
			$getarea=$area->where("id=".$getv['area_lev_5'])->find();
			$getv['a5']=$getarea['name'];
			$this->assign('vinfo',$getv);
			//书记
			$user=D('user');
			$getva=$user->where("id=".$data['u_id'])->find();
			$this->assign('vainfo',$getva);
			
		}//end if
		$this->display(); // 输出模板
	}//end fun
	
	//文章更新
	public function diary_upd(){
		$arc_diary=D('arc_diary');
		if(is_numeric($_POST['id'])){
			$data=array();
			//单文件上传
			if($_FILES['img']["name"]!=''){
				$upload = new \Think\Upload();// 实例化上传类
				$upload->maxSize   =     3145728 ;// 设置附件上传大小
				$upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
				$upload->rootPath  =      './Public/Uploads/'; // 设置附件上传根目录
				$upload->autoSub = false;	//关闭日期类型子目录自动生成
				$upload->savePath  =      'diary/'; // 设置附件上传（子）目录
				// 上传单个文件 
				$info   =   $upload->uploadOne($_FILES['img']);
				if(!$info) {// 上传错误提示错误信息
					$this->error($upload->getError());
				}else{// 上传成功 获取上传文件信息
					 $data['img']=$info['savepath'].$info['savename'];
				}
			}
			$data['u_id']=$_POST['u_id'];
			$data['v_id']=$_POST['v_id'];
			$data['title']=$_POST['title'];
			$data['content']=$_POST['content'];
			$data['uptime']=time();
			$alt=$arc_diary->where("id=".$_POST['id'])->save($data);
			if($alt>0){
				$this->success('更新成功', '/BackHome/Article/diary/');
				}else{
						//错误页面的默认跳转页面是返回前一页，通常不需要设置
						$this->error('更新失败');
				}
		}//end if
	}//end fun
	//删除
	public function diary_del(){
		$arc_diary=D('arc_diary');
		$getone=$arc_diary->where("id=".$_GET['id'])->find();//dump($getone);
		//先删除图片
		if($getone['img']!=''){
			$file = './Public/Uploads/'.$getone['img'];
			if (!unlink($file))
			  {
			  echo ("删除文件失败 $file");
			  }
			else
			  {
			  echo ("成功删除 $file");
			  }
		}
		$alt=$arc_diary->where("id=".$_GET['id'])->delete();
		if($alt>0){
			$this->success('删除成功', '/BackHome/Article/diary/');
			}else{
				$this->error('删除失败');
			}
	}//end fun
	/*******************************************************************************/
	//特色产品
    public function farming(){
        $arc_farming = M('arc_farming'); // 实例化对象
		$count      = $arc_farming->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,100);// 实例化分页类 传入总记录数和每页显示的记录数(25)
		$show       = $Page->show();// 分页显示输出
		// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
		$list = $arc_farming->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
		$newlist=array();
		foreach($list as $one){
			//后面id.title被覆盖，所以重新保存
			$one['arc_farming_id']=$one['id'];
			$one['arc_farming_title']=$one['title'];
			//原生态写法-查乡村信息
			$Model = M();
			$sql="SELECT (select name from `tv_area` where id=v.area_lev_1)as a1,(select name from `tv_area` where id=v.area_lev_2)as a2,(select name from `tv_area` where id=v.area_lev_3)as a3,(select name from `tv_area` where id=v.area_lev_4)as a4,(select name from `tv_area` where id=v.area_lev_5)as a5,v.* FROM `tv_village` v WHERE id=".$one['v_id']." order by id desc";
			$getall=$Model->query($sql);
			
			//查用户微信信息
			$user=D('user');
			$getwx=$user->where("id=".$one['u_id'])->find();
			//查用户姓名
			$user_info=D('user_info');
			$getinfo=$user_info->where("u_id=".$one['u_id'])->find();
			
			$newlist[]=array_merge($one,$getall[0],$getwx,(array)$getinfo);//合并数组其中一个为null，结果为null，需要强制类型转换(array)
		}//end for
		//dump($newlist);
		$this->assign('list',$newlist);// 赋值数据集
		$this->assign('page',$show);// 赋值分页输出
		//dump($show);
		$this->display(); // 输出模板
    }//end fun
	//添加
	public function farming_add(){
		
		$this->display(); // 输出模板
	}//end fun
	public function farming_ins(){
		$arc_farming=D('arc_farming');
		$data=array();
		//单文件上传
		if($_FILES['img']["name"]!=''){
			$upload = new \Think\Upload();// 实例化上传类
			$upload->maxSize   =     3145728 ;// 设置附件上传大小
			$upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
			$upload->rootPath  =      './Public/Uploads/'; // 设置附件上传根目录
			$upload->autoSub = false;	//关闭日期类型子目录自动生成
			$upload->savePath  =      'farming/'; // 设置附件上传（子）目录
			// 上传单个文件 
			$info   =   $upload->uploadOne($_FILES['img']);
			if(!$info) {// 上传错误提示错误信息
				$this->error($upload->getError());
			}else{// 上传成功 获取上传文件信息
				 $data['img']=$info['savepath'].$info['savename'];
			}
		}
		if($_POST['u_id']==0 || $_POST['v_id']==0)$this->error("添加失败，村庄和书记为必填项！");
		$data['u_id']=$_POST['u_id'];
		$data['v_id']=$_POST['v_id'];
		$data['title']=$_POST['title'];
		$data['content']=$_POST['content'];
		$data['pro_url']=$_POST['pro_url'];
		$data['addtime']=time();
		$data['uptime']=time();
		$alt=$arc_farming->add($data);
		if($alt>0){
			$this->success('添加成功', '/BackHome/Article/farming/');
			}else{
				    //错误页面的默认跳转页面是返回前一页，通常不需要设置
    				$this->error('新增失败');
			}
	}//end fun
	//编辑
	public function farming_edit(){
		$arc_farming=D('arc_farming');
		if(is_numeric($_GET['id'])){
			$data=array();
			$data=$arc_farming->where("id=".$_GET['id'])->find();
			$this->assign('info',$data);
			//村庄
			$village=D('village');
			$getv=$village->where('id='.$data['v_id'])->find();
			$area=D('area');
			$getarea=$area->where("id=".$getv['area_lev_1'])->find();
			$getv['a1']=$getarea['name'];
			$getarea=$area->where("id=".$getv['area_lev_2'])->find();
			$getv['a2']=$getarea['name'];
			$getarea=$area->where("id=".$getv['area_lev_3'])->find();
			$getv['a3']=$getarea['name'];
			$getarea=$area->where("id=".$getv['area_lev_4'])->find();
			$getv['a4']=$getarea['name'];
			$getarea=$area->where("id=".$getv['area_lev_5'])->find();
			$getv['a5']=$getarea['name'];
			$this->assign('vinfo',$getv);
			//书记
			$user=D('user');
			$getva=$user->where("id=".$data['u_id'])->find();
			$this->assign('vainfo',$getva);
			
		}//end if
		$this->display(); // 输出模板
	}//end fun
	
	//文章更新
	public function farming_upd(){
		$arc_farming=D('arc_farming');
		if(is_numeric($_POST['id'])){
			$data=array();
			//单文件上传
			if($_FILES['img']["name"]!=''){
				$upload = new \Think\Upload();// 实例化上传类
				$upload->maxSize   =     3145728 ;// 设置附件上传大小
				$upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
				$upload->rootPath  =      './Public/Uploads/'; // 设置附件上传根目录
				$upload->autoSub = false;	//关闭日期类型子目录自动生成
				$upload->savePath  =      'farming/'; // 设置附件上传（子）目录
				// 上传单个文件 
				$info   =   $upload->uploadOne($_FILES['img']);
				if(!$info) {// 上传错误提示错误信息
					$this->error($upload->getError());
				}else{// 上传成功 获取上传文件信息
					 $data['img']=$info['savepath'].$info['savename'];
				}
			}
			$data['u_id']=$_POST['u_id'];
			$data['v_id']=$_POST['v_id'];
			$data['title']=$_POST['title'];
			$data['content']=$_POST['content'];
			$data['pro_url']=$_POST['pro_url'];
			$data['uptime']=time();
			$alt=$arc_farming->where("id=".$_POST['id'])->save($data);
			if($alt>0){
				$this->success('更新成功', '/BackHome/Article/farming/');
				}else{
						//错误页面的默认跳转页面是返回前一页，通常不需要设置
						$this->error('更新失败');
				}
		}//end if
	}//end fun
	//删除
	public function farming_del(){
		$arc_farming=D('arc_farming');
		$getone=$arc_farming->where("id=".$_GET['id'])->find();//dump($getone);
		//先删除图片
		if($getone['img']!=''){
			$file = './Public/Uploads/'.$getone['img'];
			if (!unlink($file))
			  {
			  echo ("删除文件失败 $file");
			  }
			else
			  {
			  echo ("成功删除 $file");
			  }
		}
		$alt=$arc_farming->where("id=".$_GET['id'])->delete();
		if($alt>0){
			$this->success('删除成功', '/BackHome/Article/farming/');
			}else{
				$this->error('删除失败');
			}
	}//end fun
	/*******************************************************************************/
	//乡村夜话
    public function stories(){
        $arc_stories = M('arc_stories'); // 实例化对象
		$count      = $arc_stories->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,100);// 实例化分页类 传入总记录数和每页显示的记录数(25)
		$show       = $Page->show();// 分页显示输出
		// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
		$list = $arc_stories->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
		$newlist=array();
		foreach($list as $one){
			//后面id.title被覆盖，所以重新保存
			$one['arc_stories_id']=$one['id'];
			$one['arc_stories_title']=$one['title'];
			//原生态写法-查乡村信息
			$Model = M();
			$sql="SELECT (select name from `tv_area` where id=v.area_lev_1)as a1,(select name from `tv_area` where id=v.area_lev_2)as a2,(select name from `tv_area` where id=v.area_lev_3)as a3,(select name from `tv_area` where id=v.area_lev_4)as a4,(select name from `tv_area` where id=v.area_lev_5)as a5,v.* FROM `tv_village` v WHERE id=".$one['v_id']." order by id desc";
			$getall=$Model->query($sql);
			
			//查用户微信信息
			$user=D('user');
			$getwx=$user->where("id=".$one['u_id'])->find();
			//查用户姓名
			$user_info=D('user_info');
			$getinfo=$user_info->where("u_id=".$one['u_id'])->find();
			
			$newlist[]=array_merge($one,$getall[0],$getwx,(array)$getinfo);//合并数组其中一个为null，结果为null，需要强制类型转换(array)
		}//end for
		//dump($newlist);
		$this->assign('list',$newlist);// 赋值数据集
		$this->assign('page',$show);// 赋值分页输出
		//dump($show);
		$this->display(); // 输出模板
    }//end fun
	//添加
	public function stories_add(){
		
		$this->display(); // 输出模板
	}//end fun
	public function stories_ins(){
		$arc_stories=D('arc_stories');
		$data=array();
		//单文件上传
		if($_FILES['img']["name"]!=''){
			$upload = new \Think\Upload();// 实例化上传类
			$upload->maxSize   =     3145728 ;// 设置附件上传大小
			$upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
			$upload->rootPath  =      './Public/Uploads/'; // 设置附件上传根目录
			$upload->autoSub = false;	//关闭日期类型子目录自动生成
			$upload->savePath  =      'stories/'; // 设置附件上传（子）目录
			// 上传单个文件 
			$info   =   $upload->uploadOne($_FILES['img']);
			if(!$info) {// 上传错误提示错误信息
				$this->error($upload->getError());
			}else{// 上传成功 获取上传文件信息
				 $data['img']=$info['savepath'].$info['savename'];
			}
		}
		if($_POST['u_id']==0 || $_POST['v_id']==0)$this->error("添加失败，村庄和书记为必填项！");
		$data['u_id']=$_POST['u_id'];
		$data['v_id']=$_POST['v_id'];
		$data['title']=$_POST['title'];
		$data['content']=$_POST['content'];
		$data['addtime']=time();
		$data['uptime']=time();
		$alt=$arc_stories->add($data);
		if($alt>0){
			$this->success('添加成功', '/BackHome/Article/stories/');
			}else{
				    //错误页面的默认跳转页面是返回前一页，通常不需要设置
    				$this->error('新增失败');
			}
	}//end fun
	//编辑
	public function stories_edit(){
		$arc_stories=D('arc_stories');
		if(is_numeric($_GET['id'])){
			$data=array();
			$data=$arc_stories->where("id=".$_GET['id'])->find();
			$this->assign('info',$data);
			//村庄
			$village=D('village');
			$getv=$village->where('id='.$data['v_id'])->find();
			$area=D('area');
			$getarea=$area->where("id=".$getv['area_lev_1'])->find();
			$getv['a1']=$getarea['name'];
			$getarea=$area->where("id=".$getv['area_lev_2'])->find();
			$getv['a2']=$getarea['name'];
			$getarea=$area->where("id=".$getv['area_lev_3'])->find();
			$getv['a3']=$getarea['name'];
			$getarea=$area->where("id=".$getv['area_lev_4'])->find();
			$getv['a4']=$getarea['name'];
			$getarea=$area->where("id=".$getv['area_lev_5'])->find();
			$getv['a5']=$getarea['name'];
			$this->assign('vinfo',$getv);
			//书记
			$user=D('user');
			$getva=$user->where("id=".$data['u_id'])->find();
			$this->assign('vainfo',$getva);
			
		}//end if
		$this->display(); // 输出模板
	}//end fun
	
	//文章更新
	public function stories_upd(){
		$arc_stories=D('arc_stories');
		if(is_numeric($_POST['id'])){
			$data=array();
			//单文件上传
			if($_FILES['img']["name"]!=''){
				$upload = new \Think\Upload();// 实例化上传类
				$upload->maxSize   =     3145728 ;// 设置附件上传大小
				$upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
				$upload->rootPath  =      './Public/Uploads/'; // 设置附件上传根目录
				$upload->autoSub = false;	//关闭日期类型子目录自动生成
				$upload->savePath  =      'stories/'; // 设置附件上传（子）目录
				// 上传单个文件 
				$info   =   $upload->uploadOne($_FILES['img']);
				if(!$info) {// 上传错误提示错误信息
					$this->error($upload->getError());
				}else{// 上传成功 获取上传文件信息
					 $data['img']=$info['savepath'].$info['savename'];
				}
			}
			$data['u_id']=$_POST['u_id'];
			$data['v_id']=$_POST['v_id'];
			$data['title']=$_POST['title'];
			$data['content']=$_POST['content'];
			$data['uptime']=time();
			$alt=$arc_stories->where("id=".$_POST['id'])->save($data);
			if($alt>0){
				$this->success('更新成功', '/BackHome/Article/stories/');
				}else{
						//错误页面的默认跳转页面是返回前一页，通常不需要设置
						$this->error('更新失败');
				}
		}//end if
	}//end fun
	//删除
	public function stories_del(){
		$arc_stories=D('arc_stories');
		$getone=$arc_stories->where("id=".$_GET['id'])->find();//dump($getone);
		//先删除图片
		if($getone['img']!=''){
			$file = './Public/Uploads/'.$getone['img'];
			if (!unlink($file))
			  {
			  echo ("删除文件失败 $file");
			  }
			else
			  {
			  echo ("成功删除 $file");
			  }
		}
		$alt=$arc_stories->where("id=".$_GET['id'])->delete();
		if($alt>0){
			$this->success('删除成功', '/BackHome/Article/stories/');
			}else{
				$this->error('删除失败');
			}
	}//end fun
}//end class